package com.jjsj.mall.service.impl;

import cn.hutool.core.util.StrUtil;
import com.jjsj.mall.constant.MallConstants;
import com.jjsj.mall.entity.MallNotice;
import com.jjsj.mall.mapper.MallNoticeMapper;
import com.jjsj.mall.service.MallNoticeService;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 公告 服务层实现
 *
 * @author ruoyi
 */
@Service
@AllArgsConstructor
public class MallNoticeServiceImpl implements MallNoticeService {
    private final MallNoticeMapper noticeMapper;
    private final RedisTemplate redisTemplate;

    /**
     * 查询公告信息
     *
     * @param noticeId 公告ID
     * @return 公告信息
     */
    @Override
    public MallNotice selectNoticeById(Long noticeId) {

        String keyRedis = String.valueOf(StrUtil.format("{}:{}", MallConstants.REDIS_ORDER_KEY_IS_PAY_0, "1111"));
        redisTemplate.opsForValue().set(keyRedis, "2222", 1, TimeUnit.MINUTES);//设置过期时间
        MallNotice mallNotice = noticeMapper.selectNoticeById(noticeId);
        return mallNotice;
    }

    /**
     * 查询公告列表
     *
     * @param notice 公告信息
     * @return 公告集合
     */
    @Override
    public List<MallNotice> selectNoticeList(MallNotice notice) {
        return noticeMapper.selectNoticeList(notice);
    }

    /**
     * 新增公告
     *
     * @param notice 公告信息
     * @return 结果
     */
    @Override
    public int insertNotice(MallNotice notice) {
        return noticeMapper.insertNotice(notice);
    }

    /**
     * 修改公告
     *
     * @param notice 公告信息
     * @return 结果
     */
    @Override
    public int updateNotice(MallNotice notice) {
        return noticeMapper.updateNotice(notice);
    }

    /**
     * 删除公告对象
     *
     * @param noticeId 公告ID
     * @return 结果
     */
    @Override
    public int deleteNoticeById(Long noticeId) {
        return noticeMapper.deleteNoticeById(noticeId);
    }

    /**
     * 批量删除公告信息
     *
     * @param noticeIds 需要删除的公告ID
     * @return 结果
     */
    @Override
    public int deleteNoticeByIds(Long[] noticeIds) {
        return noticeMapper.deleteNoticeByIds(noticeIds);
    }
}
